/**
 * 
 */
package com.gragra.sampling.nonproj.structures.nonprojective.singleroot;
import java.util.BitSet;
import com.gragra.sampling.PopulationProbabilityAssigner;
import com.gragra.sampling.binary.ConvertSample;
import com.gragra.sampling.nonproj.structures.nonprojective.NonProjDepdTree;
import com.gragra.sampling.sequentialStructure.WordAndTagHolder;
/**
 * @author Christoph Teichmann
 * 10.10.2013
 */
public abstract class SingleRootNonProjDepdTree extends NonProjDepdTree
{
	/* (non-Javadoc)
	 * @see com.gragra.sampling.nonproj.NonProjDepdTree#attach(int, int, int)
	 */
	@Override
	protected void attach(int forPosition, int toHead, int inThread)
	{
		if(toHead==this.getRootPosition())
		{currentRoots[inThread] = forPosition;}
		super.attach(forPosition, toHead, inThread);
	}
	/**
	 * 
	 * @param thread
	 * @return
	 */
	public int getCurrentRoot(int thread)
	{return this.currentRoots[thread];}
	/**
	 * 
	 */
	private final int[] currentRoots;
	/* (non-Javadoc)
	 * @see com.gragra.sampling.nonproj.NonProjDepdTree#makeAllHeadCandidates(int, int, com.gragra.sampling.PopulationProbabilityAssigner)
	 */
	@Override
	protected BitSet makeAllHeadCandidates(int pos, int thread,
			PopulationProbabilityAssigner npa)
	{
		BitSet bs = super.makeAllHeadCandidates(pos, thread, npa);
		if(this.getDaughters(this.getRootPosition(), thread).cardinality()>0)
		{bs.clear(this.getRootPosition());}
		return bs;
	}
	/* (non-Javadoc)
	 * @see com.gragra.sampling.nonproj.NonProjDepdTree#skip(int, com.gragra.sampling.PopulationProbabilityAssigner, int)
	 */
	@Override
	protected boolean skip(int pos, PopulationProbabilityAssigner pa, int thread)
	{return this.getCurrentRoot(thread)==pos;}
	/**
	 * 
	 * @param wth
	 * @param threads
	 * @param cs
	 */
	public SingleRootNonProjDepdTree(WordAndTagHolder wth, int threads,
			ConvertSample cs)
	{
		super(wth, threads, cs);
		this.currentRoots = new int[threads];
	}
}